﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Order
{
    /// <summary>
    /// 生成订单
    /// </summary>
    /// <param name="userID"></param>
    /// <returns></returns>
    public int Add(int userID, out int orderID)
    {
        DataModelDataContext data = new DataModelDataContext();
        orderID = data.CreatOrder(userID);
        return (orderID > 0) ? 1 : 0;
    }

    /// <summary>
    /// 修改发货方式
    /// </summary>
    /// <param name="orderID"></param>
    /// <param name="sendwayID"></param>
    /// <returns></returns>
    public void UpdateSendway(int orderID, int sendwayID)
    {
        DataModelDataContext data = new DataModelDataContext();
        data.Pr_UpdateDeliveryMode(orderID, sendwayID);
    }

    /// <summary>
    /// 修改订单状态
    /// </summary>
    /// <param name="orderID"></param>
    /// <param name="orderstate"></param>
    /// <returns></returns>
    public void UpdateState(int orderID, string orderstate)
    {
        DataModelDataContext data = new DataModelDataContext();
        data.Pr_UpdateOrderState(orderID, orderstate);
    }

    /// <summary>
    /// 获得所有订单
    /// </summary>
    /// <returns></returns>
    public DataTable GetAllOrders()
    {
        DataModelDataContext data = new DataModelDataContext();
        var result = data.Pr_GetAllOrders();
        DataTable table = new DataTable();
        table = result.CopyToDataTable();
        return table;
    }

    /// <summary>
    /// 获得指定用户的所有定单 
    /// </summary>
    /// <param name="userid"></param>
    /// <returns></returns>
    public DataTable GetOrdersByUser(int userID)
    {
        DataModelDataContext data = new DataModelDataContext();
        var result = data.Pr_GetOrdersByUser(userID);
        DataTable table = new DataTable();
        table = result.CopyToDataTable();
        return table;
    }

    /// <summary>
    /// 获得某个订单的信息
    /// </summary>
    /// <param name="orderid"></param>
    /// <returns></returns>
    public DataTable GetOrderByID(int orderID)
    {
        DataModelDataContext data = new DataModelDataContext();
        var result = data.Pr_GetOrderByID(orderID);
        DataTable table = new DataTable();
        table = result.CopyToDataTable();
        return table;
    }
}
